<?php
include 'util/BeanJSONEncoder.php';
include 'util/BeanJSONDecoder.php';

class PresentController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function relevantAction() {
    	$ps = new Application_Model_PersistenceService();
    	$presents = $ps->findRelevantPresents($_GET['conversation']);
    	//$presents = $ps->findRelevantPresents($_GET['conversation']);
    	$json = Application_util_BeanJSONEncoder::encode($presents);
    	$this->getResponse()->setHeader('Content-Type', 'application/json')
                                ->setBody($json)->sendResponse();
        exit;
    }
    
	public function findAction() {
		if ($this->_hasParam('name')) {
			$ps = new Application_Model_PersistenceService();
			
			$presents = $ps->findPresentByName($this->_getParam('name'), false);
			
			$json = '[';
			$first = true;
			foreach ($presents as $p){
				if (!$first) {
					$json.=',';
				} else {
					$first = false;
				}
				$json.= '"'.$p->getName().'"';
			}
			$json.= ']';
			$this->getResponse()->setHeader('Content-Type', 'application/json')
                                ->setBody($json)->sendResponse();
		}
		exit;
	}

}

